<!-- 上传文件  -->
<template>
  <el-upload
    class="upload-demo"
    :action="uploadURL + 'busRfidTemplate/uploadTemp'"
    :data="{ templateStyle: templateId }"
    :show-file-list="false"
    :headers="headers"
    :on-success="handleAvatarSuccess"
    :before-upload="beforeAvatarUpload"
    style="display: inline-block; margin-left: 10px"
  >
    <el-button type="primary" size="small">{{ buttonText }}</el-button>
  </el-upload>
</template>

<script>
export default {
  name: 'uploadFile',
  props: {
    uploadURL: {
      type: String,
      default: ''
    },
    buttonText: {
      type: String,
      default: '上传打印模版',
    },
    templateId: {
      type: Number,
      default: 0,
    },
  },
  components: {},
  data() {
    return {
      headers: {
        'X-Access-Token': localStorage.getItem('X-Access-Token'),
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    handleAvatarSuccess(res, file) {
      if (res.code === 200) {
        this.$message.success(res.message)
      } else {
        this.$message.error(res.message)
      }
    },
    beforeAvatarUpload(res, file) {
      if (res.name.indexOf('.lsf') === -1) {
        this.$message.warning('请上传.lsf文件')
        return false
      }
    },
  },
}
</script>
<style lang="less" scoped></style>
